//
//  ViewController.m
//  ControlFUn
//
//  Created by student on 16/2/18.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end


// 练习:
// 1. 编写doSomething按钮的事件处理方法
//    1.1 点击按钮弹出操作表,见图10501B.png
//    1.2 编写提示框的代理方法,如果点的是"是的,我确定"项,则弹出消息框,见10501C.png
// 2. 纯代码方式实现本程序
//纯代码方式修改view为UIControl类对象 见给出的例子

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
    // 设置doSomething按钮的背景(需要对图片进行拉伸设置）
    // 1. 代码方式
    //    // 代码实现设置按钮的背景图片
    //    UIImage *img1 = [UIImage imageNamed:@"whiteButton"];
    //    UIImage *img2 = [UIImage imageNamed:@"blueButton"];
    //
    //    // 创建拉伸的图片 (左右各留12像素不拉伸)
    //    UIEdgeInsets insets = UIEdgeInsetsMake(0, 12, 0, 12);// 上左下右
    //    UIImage *img3 = [img1 resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
    //    UIImage *img4 = [img2 resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
    //
    //    [self.doSomethingBtn setBackgroundImage:img3 forState:UIControlStateNormal];
    //    [self.doSomethingBtn setBackgroundImage:img4 forState:UIControlStateHighlighted];
    
    // 2. 删除原来拖到项目中的图片，重新拉图片放在Assets.scassets中,用Assets.scassets管理图片。
    //设置一下需要拉伸的图片的切片,图片被使用的时候会自动拉伸
}




//分段控件改变触发的方法
- (IBAction)segementChanged:(UISegmentedControl *)sender
{
    if (sender.selectedSegmentIndex == 0)
    {
        self.leftSwitch.hidden = NO;
        self.rightSwitch.hidden = NO;
        self.doSomethingBtn.hidden = YES;
    }
    else
    {
        self.leftSwitch.hidden = YES;
        self.rightSwitch.hidden = YES;
        self.doSomethingBtn.hidden = NO;
    }
}
- (IBAction)switchChanged:(UISwitch *)sender
{
    BOOL open = sender.on;
    [self.leftSwitch setOn:open animated:YES];
    [self.rightSwitch setOn:open animated:NO];
}
- (IBAction)doSomethingBtnPressed:(id)sender
{
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"一起嗨皮吗？"
                                                       delegate:self
                                              cancelButtonTitle:@"好的一起嗨皮"
                                         destructiveButtonTitle:@"脑抽吧，不好好睡觉嗨毛皮"
                                              otherButtonTitles:@"看哥哥心情",@"我请客你买单",nil];
    [sheet showInView:self.view];
}


//滑动条滑动触发的方法
- (IBAction)sliderChanged:(UISlider *)sender
{
    int value = sender.value;
    //把滑动条的值显示到Label上
    self.sliderValueLabel.text = [NSString stringWithFormat:@"%i",value];
}

- (IBAction)backTap:(id)sender
{
    [self.view endEditing:YES];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == actionSheet.cancelButtonIndex)
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"弹出" message:[actionSheet buttonTitleAtIndex:buttonIndex] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
        
        [alertView show];
    }
}
@end
